<template>
	<view class="content">
		<u-navbar :autoBack="true" bgColor="rgba(0,0,0,0)" :fixed="true" @click-left="$back" ></u-navbar>
		
		<image :src="'/images/login-bg.png' | formatImgUrl" class="bei" mode=""></image>
		<view class="title">
			绑定手机号
		</view>
		<view class="weitxt">
			为了保护帐号安全,请绑定手机号
		</view>
		<view class="baibox">
			<view class="left">
				<view class="letxt">
					+86
				</view>
				<image :src="'/images/duo.png' | formatImgUrl" class="lepic" mode=""></image>
			</view>
			<u--input class="baiput" placeholder="请输入手机号" border="surround" clearable type="number" maxlength="11" v-model="mobile"></u--input>
		</view>
		<view class="baibox">
			<u-input placeholder="请输入6位验证码" class="baiput" border="surround" clearable type="number" maxlength="6" v-model="code">
				<view slot="suffix">
					<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X"></u-code>
					<u-button @tap="getCode" class="huo"   :text="tips" type="success" size="mini"></u-button>
				</view>
			</u-input>
		</view>
		<view class="xiebox" @click="isRead =( isRead == 2?0:2)" :class="isRead == 1 ? 'shake-horizontal' : ''">
			<label>
				<!-- <checkbox style="transform: scale(0.7);" :checked="isRead" /> -->
				<u-checkbox shape="circle" size="14" :checked="isRead" activeColor="#45C4B0" inactiveColor="#999" @change="changeBox"></u-checkbox>
			</label>
			<view class="xietxt">
				我已阅读并同意：<text @click.stop="goToxie">《服务协议》</text>和<text @click.stop="goToOtherxie(14)">《隐私政策》</text>
			</view>
		</view>
		<view class="lubox" @click="toLogin">
			确认绑定
		</view>
		<!-- <view class="dlbox">
			<view class="dltxt" @click="ht()">
				账号密码登录
			</view>
		</view> -->
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isRead: false,
				tips: '获取验证码',
				code: '',
				mobile:''
			}
		},
		onLoad() {},
		methods: {
			changeBox(e){
				this.isRead = e ? 2 : 0
			},
			ht(){
				uni.navigateBack({//返回上一个页面
					delta: 1
				});
			},
			goToxie(){
				uni.navigateTo({
					url:'/pages/webview/webview?url=' +this.$config.default.Url + '/agreement/1000000'
				})
			},
			goToxiea(){
				uni.navigateTo({
					url:'/pages/webview/webview?url=' +this.$config.default.Url + '/agreement/1000001'
				})
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$api.default.request('user/sendSms2', {
						mobile: this.mobile,
					}).then((res) => {
						if (res.code) {
							uni.hideLoading();
							// 这里此提示会被this.start()方法中的提示覆盖
							uni.$u.toast(res.msg);
							// 通知验证码组件内部开始倒计时
							this.$refs.uCode.start();
						}else{
							this.$common.errorToShow(res.msg)
						}
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			toLogin(){
				if (!this.isRead) {
					this.isReadTip()
				}else{
					this.$api.default.request('user/smsLogin_bingd', {
						mobile: this.mobile,
						verify_code:this.code
					}).then((res) => {
						if (res.code) {
							this.$db.set('auth',res.token)
							this.$db.set('userInfo',res.user)
							getApp().getIMchat()
							
							// if(!res.user.like_content_tags && !res.user.like_writer_tags){
							// 	uni.reLaunch({
							// 		url:'/pages/login/hobby'
							// 	})
							// }else{
								uni.reLaunch({
									url:'/pages/index/index'
								})
							// }
						}else{
							this.$common.errorToShow(res.msg)
						}
					})
				}
			},
			isReadTip() {
				if (!this.isRead) {
					this.$common.errorToShow('请先同意用户协议');
					this.isRead = 1
					setTimeout(() => {
						this.isRead = 0;
					}, 300)
					return
				}
			},
			change(e) {
				console.log('change', e);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		position: relative;
		padding: 80rpx 60rpx;
		padding-top: 154px;

		.bei {
			width: 100%;
			height: 100vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
		}

		.title {
			font-size: 48rpx;
			font-weight: bold;
			letter-spacing: 0.08em;
			line-height: 70rpx;
			color: #3D3D3D;
			padding-bottom: 16rpx;
		}

		.weitxt {
			font-size: 24rpx;
			font-weight: normal;
			letter-spacing: 0.24em;
			color: #999999;
			padding-bottom: 60rpx;
		}

		.baibox {
			padding: 0 28rpx;
			height: 98rpx;
			border-radius: 8px;
			opacity: 1;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;
			.left {
				display: flex;
				align-items: center;
				flex-shrink: 0;
				padding-right: 16rpx;
				.letxt {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					padding-right: 6rpx;
				}

				.lepic {
					width: 16rpx;
					height: 12rpx;
				}
			}

			.baiput {
				padding-left: 14rpx;
				flex-grow: 1;
				font-size: 32rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
			}
			.huo{
				color: #45C4B0 !important;
				font-size: 32rpx !important;
				font-weight: bold !important;
			}
		}

		.xiebox {
			display: flex;
			align-items: center;
			padding-bottom: 32rpx;
			.xietxt {
				font-size: 24rpx;
				color: #999999;

				text {
					font-size: 24rpx;
					font-weight: bold;
					color: #45C4B0;
					padding: 0 10rpx;
				}
			}
		}
		.lubox{
			width: 630rpx;
			height: 86rpx;
			border-radius: 8px;
			line-height: 86rpx;
			margin: 0 auto 20rpx;
			opacity: 1;
			background: #45C4B0;
			font-size: 32rpx;
			font-weight: bold;
			letter-spacing: 0em;
			text-align: center;
			color: #FFFFFF;
			border: 1px solid #45C4B0;
		}
		.u-border {
			border-width: 0 !important;
			padding: 0 !important;
		}

		.u-input__content__field-wrapper__field {
			font-size: 32rpx !important;
			letter-spacing: 0em !important;
			color: #3D3D3D !important;
		}
		.u-button--mini.data-v-3bf2dba7 {
		    color: #45C4B0 !important;
		    font-size: 32rpx !important;
		    font-weight: bold !important;
			padding: 0 !important;
			min-width: none !important;
		}
		.u-button__text{
			font-size: 32rpx !important;
			font-weight: bold !important;
		}
		.dlbox{
			display: flex;
			align-items: center;
			justify-content: space-between;
			.dltxt{
				font-size: 24rpx;
				font-weight: bold;
				letter-spacing: 0.08em;
				color: #45C4B0;
			}
		}
	}
</style>